package cn.suhaoblog.config.swagger;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
@Slf4j
public class SwaggerConfig {

    // 配置控制层所在模块路径, swagger会自动扫描所有接口, 生成接口文档
    @Bean
    public Docket createRestApi() {
        log.info("初始化Swagger成功!");
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.suhaoblog"))
                .paths(PathSelectors.any())
                .build();
    }

    // 基本信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("书签等所有模块接口列表")
                .termsOfServiceUrl("http://www.suhaoblog.cn")
                .version("1.0")
                .build();
    }
}
